import time
import threading

class Spider(threading.Thread):
    def __init__(self,name,q):
        threading.Thread.__init__(self)
        self.queuelock = threading.Lock()
        self.name = name
        self.q = q

    def run(self):
        self.process(self.name, self.q)

    def process(self, name, q):
        while not q.empty():
            self.queuelock.acquire()
            if not q.empty():
                url = q.get()
                self.queuelock.release()

                # results from crawler, put to queue
                #_url = url+"."

                #self.queuelock.acquire()
                #q.put(_url)
                #self.queuelock.release()

                print ("%s processing %s" % (name, url))
            else:
                self.queuelock.release()


            time.sleep(1)
